package com.sixth.volunteerservicesystem.Service.impl;

import com.sixth.volunteerservicesystem.Service.IBackendUserinfoService;
import com.sixth.volunteerservicesystem.domain.CURDResult;
import com.sixth.volunteerservicesystem.domain.PageResult;
import com.sixth.volunteerservicesystem.domain.Users;
import com.sixth.volunteerservicesystem.mapper.BackendUserinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class BackendUserinfoServiceImpl implements IBackendUserinfoService {
    @Autowired(required=false)
    BackendUserinfoMapper backendUserinfoMapper;
    @Override
    public PageResult<Users> findUserPageResult(Users condition, int page, int pageSize) {
        PageResult<Users> result = new PageResult<>();
        result.setCode(0);

        HashMap<String, Object> params = new HashMap<>();

        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);


        // 获取总记录数
        int totalCount = backendUserinfoMapper.findCountByMap(params);
        result.setCount(totalCount);
        List<Users> list = backendUserinfoMapper.findListByMap(params);

        result.setData(list);
        return result;
    }

    @Override
    public CURDResult userinfosave(Users user) {
        backendUserinfoMapper.userinfoinset(user);
        return null;
    }

    @Override
    public Users findUserByuserId(String userId) {
        return backendUserinfoMapper.findByuserId(userId);
    }
}
